package com.blb.zy_community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.zy_community.entity.ResponseResult;
import com.blb.zy_community.entity.SysLogininfor;
import com.blb.zy_community.service.ISysLogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author 二组
 * @since 2023-06-18
 */
@CrossOrigin
@RestController
public class SysLogininforController {
    @Autowired
    private ISysLogininforService sysLogininforService;

    /**
     * 获取分页数据
     * @param current           当前页数
     * @param size              每页有几行
     * @param ipaddr            ip地址
     * @param userName          用户名
     * @param status            状态
     * @param loginTimeRangeStart    登录时间筛选的范围_起始
     * @param loginTimeRangeEnd    登录时间筛选的范围_结束
     * @return
     */
    @GetMapping("/sysLoginInfor/page")
    public ResponseResult<Page<SysLogininfor>> getSysLogininforPage(
            @RequestParam(required = false,defaultValue = "1") Long current,
            @RequestParam(required = false,defaultValue = "5") Long size,
            @RequestParam(required = false) String ipaddr,
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String loginTimeRangeStart,
            @RequestParam(required = false) String loginTimeRangeEnd

    ){
        Page<SysLogininfor> sysLogininforPage= sysLogininforService.getSysLogininforPage(new Page<>(current,size),ipaddr,userName,status,loginTimeRangeStart,loginTimeRangeEnd);
        return ResponseResult.ok(sysLogininforPage);

    }

    /**
     * 登录日志批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/sysLoginInfor/batchDelete/{ids}")
    public ResponseResult<Long[]> batchDeleteBySysOperLogIds(@PathVariable("ids") String[] ids) {
        List<String> list = Arrays.asList(ids);
        sysLogininforService.removeBatchByIds(list);
        return ResponseResult.ok(ids);
    }
}
